import { STOCK_TYPE } from "lib/tschart/src/lib/name-types";
export { STOCK_TYPE };

const TYPE_PROP_NAME = "market";

export const getStockType = stock => {
  return !stock || !stock[TYPE_PROP_NAME] ? 0 :
    stock[TYPE_PROP_NAME].indexOf("MRI") === -1 && stock[TYPE_PROP_NAME].indexOf("XBHS") === -1 ? 0 :
      stock[TYPE_PROP_NAME].indexOf("MRI") !== -1 ? 1 : 2;
}

const INDEXES = ["000001.SS", "399001.SZ", "399006.SZ"];

export const getStockTypeThree = stock => {
  console.debug("Get Stock Type: ", stock);
  if (!stock || !stock.market) return STOCK_TYPE.INDEX;
  if (INDEXES.indexOf(stock.symbol) !== -1) {
    return STOCK_TYPE.INDEX;
  } else if (stock.market.indexOf("MRI") !== -1) {
    return STOCK_TYPE.INDEX;
  } else if (stock.market.indexOf("XBHS") !== -1) {
    return STOCK_TYPE.BLOCK;
  } else {
    return STOCK_TYPE.STOCK;
  }
}

export const getStockTypeThreeOld = stock => {
  return !stock || !stock[TYPE_PROP_NAME]
    ? STOCK_TYPE.STOCK
    : INDEXES.indexOf(stock["symbol"]) !== -1
      ? STOCK_TYPE.INDEX // 是否三大股指
      : stock[TYPE_PROP_NAME].indexOf("MRI") === -1 && stock[TYPE_PROP_NAME].indexOf("XBHS") === -1 // 是否非股指非板块
        ? STOCK_TYPE.STOCK
        : STOCK_TYPE.BLOCK
}